package com.lsh.controller;

import com.lsh.pojo.Result;
import com.lsh.pojo.Stu_Co;
import com.lsh.service.Stu_CoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/stu-management")
public class Stu_CoController {

    @Autowired
    private Stu_CoService stu_coService;

    @GetMapping("stu-co")
    public Result list() {
        List<Stu_Co> sc = stu_coService.list();
        return Result.success(sc);
    }

    @PostMapping("/getByStu-Co")
    public Result getByStu_Co(@RequestBody Stu_Co sc) {
//        log.info("联合查询数据：{}",sc);
        Stu_Co stu_co = stu_coService.getByStu_Co(sc);
        if (stu_co == null) {
            return Result.error("未查找到选课信息！");
        }
        return Result.success(stu_co);
    }

    @GetMapping ("/getCoBySno")
    public Result getStuBySno(@RequestParam String sno) {
        log.info("查询学生选课：{}",sno);
        List<Stu_Co> sc = stu_coService.getBysno(sno);
        return Result.success(sc);
    }

}
